﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using QLST_DTO;

namespace QLST_DAO
{
    public class HANGHOADAO : TempDAO
    {
        /// <summary>
        /// Hàm lấy danh sách sản phẩm
        /// </summary>
        /// <returns></returns>
        public DataTable GetSanPham()
        {
            DataTable tbl = dap.ExcuteProcedureGetTable("st_GetSanPham", null);
            if (tbl.Rows.Count < 0)
            {
                return null;
            }
            return tbl;
        }
        /// <summary>
        /// Lay chi tiet hang hoa theo MaSo
        /// </summary>
        /// <param name="MaHang"></param>
        /// <returns></returns>
        public HANG_HOA Get(int MaHang)
        {
            HANG_HOA hh = new HANG_HOA();
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@MaHang", MaHang);
            DataTable tbl = dap.ExcuteProcedureGetTable("st_GetSanPhamTheoMa", parameters);
            if (tbl.Rows.Count > 0)
            {
                DataRow dr = tbl.Rows[0];

                hh.MaHang = int.Parse(dr["MaHang"].ToString());
                hh.TenHang = dr["TenHang"].ToString();
                hh.SoLuong = int.Parse(dr["SoLuong"].ToString());
                hh.DonGia = float.Parse(dr["DonGia"].ToString());
                hh.DVT = dr["DVT"].ToString();
                hh.ChungLoai = dr["ChungLoai"].ToString();
                hh.MaNVQL = int.Parse(dr["MaNVQL"].ToString());
                hh.MaNVPP = int.Parse(dr["MaNVPP"].ToString());
                hh.MaLoaiHang = int.Parse(dr["MaLoaiHang"].ToString());
                //hh.HinhAnh =  dr["HinhAnh"].ToString();
                hh.GiaBan = float.Parse(dr["GiaBan"].ToString());
                hh.DinhMucTonKho = int.Parse(dr["DinhMucTonKho"].ToString());

            }

            return hh;

        }
    }
}
